home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / group / groups.c next >
C/C++ Source or Header  |  1996-07-10  |  11KB  |  457 lines

  1. /*************************************************************
  2.  * GROUPS.C
  3.  * Version 2.0 - list groups full name
  4.  * Version 2.1 - list group members
  5.  * Version 2.2 - added /a switch
  6.  */
  7.  
  8. /*************************************************************
  9.  * usage:
  10.  *  groups            - lists group names, id no, & full name
  11.  *  groups /a         - lists all groups and their members
  12.  *  groups group name - lists members of that group
  13.  */
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <dos.h>
  18. #include <ctype.h>
  19.  
  20. char myname[] = "Patrick L. McGillan";
  21. char mydate[] = "November 24, 1989";
  22. char myvers[] = "Groups Version 2.2";
  23.  
  24. struct REGPACK Regs;
  25.  
  26. typedef unsigned char BYTE;
  27.  
  28. typedef struct {
  29.          unsigned char ah, al, bh, bl;
  30.                } LONG;
  31.  
  32. typedef struct {
  33.          char wh, wl;
  34.                } WORD;
  35.  
  36. typedef struct {
  37.          char wl, wh;
  38.                } NATIVE;
  39.  
  40. typedef struct {                    /* send packet format for e3(36h)    */
  41.          NATIVE SL;         /* packet length                    */
  42.                  BYTE   FNC;          /*  $36 for get object name      */
  43.          LONG   UOID;       /*  Unique ID for the object     */
  44.                } e336cl;
  45.  
  46. typedef struct {                    /* return packet format for e3(36h)    */
  47.          NATIVE RL;         /* return length                */
  48.          LONG   UOID;       /*  same id as above                */
  49.          WORD   OT;         /*  type of object                  */
  50.          BYTE   ON[48];
  51.                } e336rp;
  52.  
  53. typedef struct {                    /* send packet format for e3(46h)   */
  54.          NATIVE SL;         /* send packet length               */
  55.          BYTE   FNC;        /*  $46 = get  bindery access level */
  56.                } chkcall;
  57.  
  58. typedef struct {                    /* return packet format for e3(36h) */
  59.          NATIVE RL;         /* return length                    */
  60.                  BYTE   AL;         /* access level allowed             */
  61.          LONG   MOID;       /* My Object ID                     */
  62.                } chkrply;
  63.  
  64. typedef struct {                    /* send packet format for e3(37h)   */
  65.          NATIVE SL;         /* send packet length               */
  66.          BYTE   FNC;        /*  55 for Search for Users         */
  67.          LONG   LOS;        /*  make it -1                      */
  68.          WORD   PT;         /*  Search for users 0001           */
  69.          BYTE   PL;         /*  1                               */
  70.          BYTE   SP[48];     /*  *, if search all is used        */
  71.                } e33dcall;
  72.  
  73. typedef struct {                    /* return packet format for e3(37h) */
  74.          NATIVE RL;         /* return packet length             */
  75.          LONG   UOID;       /* unique object id code            */
  76.          WORD   OT;         /* object type                      */
  77.          BYTE   ON[48];     /* object name                      */
  78.                  BYTE   OF;         /* objects flags                    */
  79.                  BYTE   OS;         /* objects security                 */
  80.                  BYTE   PE;         /* properties exist                 */
  81.              }  e33drply;
  82.  
  83. typedef struct {                    /* send packet format for e3(3dh)   */
  84.          NATIVE SL;         /* send packet length               */
  85.          BYTE   FNC;        /* 55 for Search for Users          */
  86.          WORD   OT;         /* object type                      */
  87.          BYTE   ONL;        /* object name length               */
  88.          BYTE   ON[48];     /* object name                      */
  89.                  BYTE   SN;         /* segment number                   */
  90.                  BYTE   PNL;        /* property name length             */
  91.          BYTE   PN[48];     /* property name                    */
  92.                } e33prvcall;
  93.  
  94. typedef struct {                    /* return packet format for e3(3dh) */
  95.          NATIVE RL;         /* return packet length             */
  96.          BYTE   DT[128];    /* data                             */
  97.                  BYTE   MR;         /* more                             */
  98.                  BYTE   PF;         /* property flags                   */
  99.              }  e33prvrply;
  100.  
  101.  
  102. typedef struct {                    /* send packet format for e3(36h)   */
  103.                  NATIVE SL;
  104.                  BYTE   FNC;
  105.                  LONG   UOID;
  106.                } e33gncall;
  107.  
  108.  
  109. typedef struct {
  110.                  NATIVE RL;
  111.                  LONG   UOID;
  112.                  WORD   OT;
  113.                  BYTE   ON[48];
  114.                } e33gnrply;
  115.  
  116. e33gncall   gnc;
  117. e33gnrply   gnr;
  118.  
  119. e336cl       nc;
  120. e336rp       nr;
  121.  
  122. chkcall      cc;
  123. chkrply      cr;
  124.  
  125. e33dcall     pc;
  126. e33drply     pr;
  127.  
  128. e33prvcall   vc;
  129. e33prvrply   vr;
  130.  
  131. void Users (nam)
  132. char *nam;
  133. {
  134.     unsigned int SBO;
  135.     int     i, once = 0, first = 1, all = 0;
  136.  
  137.     if (strlen(nam) < 1)
  138.         strcpy (nam, "*");
  139.     else
  140.     {
  141.         all = 1;
  142.         once = 1;
  143.     }
  144.  
  145.     if ((strcmp("/a", nam) == 0) || (strcmp("/A", nam) == 0))
  146.     {
  147.         strcpy (nam, "*");
  148.         all = 1;
  149.         once = 0;
  150.     }
  151.  
  152.     do
  153.     {
  154.         SBO = scan_bind(first, nam);
  155.         if ((SBO & 0x00ff) == 0)
  156.         {
  157.             printf ("\n\n%s", pr.ON);
  158.             for (i=(12-strlen(pr.ON));i>0;--i)
  159.                 printf (" ");
  160.             prntbyt(pr.UOID.ah);
  161.             prntbyt(pr.UOID.al);
  162.             prntbyt(pr.UOID.bh);
  163.             prntbyt(pr.UOID.bl);
  164.             print_name(pr.ON);
  165.             if (all)
  166.                 read_members(pr.ON);
  167.         }
  168.         first = 0;
  169.     } while (((SBO & 0x00ff) == 0) && (!once));
  170. }
  171.  
  172.  
  173. print_name (name)
  174. char *name;
  175. {
  176.     unsigned int RPV;
  177.  
  178.     vr.RL.wh = 0;            
  179.     vr.RL.wl = 130;
  180.  
  181.     vc.SL.wh = 0;
  182.     vc.SL.wl = 102;
  183.  
  184.     vc.FNC = 0x3d;
  185.  
  186.     vc.OT.wh = 0;
  187.     vc.OT.wl = 2;
  188.  
  189.     vc.SN = 1;
  190.  
  191.     vc.ONL = 48;
  192.     vc.PNL = 48;
  193.  
  194.     strcpy (vc.ON, name);
  195.     strcpy (vc.PN, "IDENTIFICATION");
  196.  
  197.     Regs.r_ax = 0xE300;
  198.  
  199.     Regs.r_es = FP_SEG (&vr);
  200.     Regs.r_di = FP_OFF (&vr);
  201.  
  202.     Regs.r_ds = FP_SEG (&vc);
  203.     Regs.r_si = FP_OFF (&vc);
  204.  
  205.     intr (33, &Regs);
  206.     RPV = Regs.r_ax;
  207.  
  208.     if ((RPV & 0x00ff) == 0)
  209.         printf ("  %s", vr.DT);
  210.  
  211. }
  212.  
  213.  
  214.  
  215. read_members (name)
  216. char *name;
  217. {
  218.     unsigned int RPV;
  219.     int infirst = 1;
  220.  
  221.     do
  222.     {
  223.         vr.RL.wh = 0;            
  224.         vr.RL.wl = 130;
  225.  
  226.         vc.SL.wh = 0;
  227.         vc.SL.wl = 102;
  228.  
  229.         vc.FNC = 0x3d;
  230.  
  231.         vc.OT.wh = 0;
  232.         vc.OT.wl = 2;
  233.  
  234.         if (infirst)
  235.         {
  236.             vc.SN = 1;
  237.             infirst = 0;
  238.         }
  239.         else
  240.             vc.SN = vc.SN + 1;
  241.  
  242.         vc.ONL = 48;
  243.         vc.PNL = 48;
  244.  
  245.         strcpy (vc.ON, name);
  246.         strcpy (vc.PN, "GROUP_MEMBERS");
  247.  
  248.         Regs.r_ax = 0xE300;
  249.  
  250.         Regs.r_es = FP_SEG (&vr);
  251.         Regs.r_di = FP_OFF (&vr);
  252.  
  253.         Regs.r_ds = FP_SEG (&vc);
  254.         Regs.r_si = FP_OFF (&vc);
  255.  
  256.         intr (33, &Regs);
  257.         RPV = Regs.r_ax;
  258.  
  259.         if ((RPV & 0x00ff) == 0)
  260.             get_name(vr.DT);
  261.  
  262.     } while ((vr.MR == 0xff) && ((RPV & 0x00ff) == 0));
  263. }
  264.  
  265.  
  266. get_name(ids)
  267. char *ids;
  268. {
  269.     unsigned int GON;
  270.     int i = 0, j, k = 0;
  271.  
  272.     printf ("\n");
  273.  
  274.     do
  275.     {
  276.         gnr.RL.wh = 0;
  277.         gnr.RL.wl = 54;
  278.  
  279.         gnc.SL.wh = 0;
  280.         gnc.SL.wl = 5;
  281.  
  282.         gnc.FNC = 0x36;
  283.  
  284.         gnc.UOID.ah = ids[i++];
  285.         gnc.UOID.al = ids[i++];
  286.         gnc.UOID.bh = ids[i++];
  287.         gnc.UOID.bl = ids[i++];
  288.  
  289.         Regs.r_ax = 0xE300;
  290.  
  291.         Regs.r_es = FP_SEG (&gnr);
  292.         Regs.r_di = FP_OFF (&gnr);
  293.  
  294.         Regs.r_ds = FP_SEG (&gnc);
  295.         Regs.r_si = FP_OFF (&gnc);
  296.  
  297.         intr (33, &Regs);
  298.         GON = Regs.r_ax;
  299.  
  300.         if ((GON & 0x00ff) == 0)
  301.         {
  302.             printf ("  %s", gnr.ON);
  303.             for (j=(12-strlen(gnr.ON));j>0;--j)
  304.                 printf (" ");
  305.             if (k == 3)
  306.             {
  307.                 printf ("\n");
  308.                 k = 0;
  309.             }
  310.             else
  311.                 ++k;
  312.         }
  313.     } while (i < 128);
  314. }
  315.  
  316. scan_bind (first, nam)
  317. int first;
  318. char *nam;
  319. {
  320.     if (first)
  321.     {
  322.         pc.LOS.ah = 0x1f;   /*  set the last object seen to -1  */
  323.         pc.LOS.al = 0xff;
  324.         pc.LOS.bh = 0xff;
  325.         pc.LOS.bl = 0xff;
  326.     }
  327.     else
  328.     {
  329.         pc.LOS.ah = pr.UOID.ah;   /*  set the last object seen to   */
  330.         pc.LOS.al = pr.UOID.al;   /*  the last object seen */
  331.         pc.LOS.bh = pr.UOID.bh;
  332.         pc.LOS.bl = pr.UOID.bl;
  333.     }
  334.             
  335.     pr.RL.wh = 0;
  336.     pr.RL.wl = 57;
  337.  
  338.     pc.SL.wh = 0;
  339.     pc.SL.wl = 58;
  340.  
  341.     pc.FNC = 0x37;   /*  scan bindery objects  */
  342.  
  343.     pc.PT.wh = 0;
  344.     pc.PT.wl = 2;
  345.  
  346.     pc.PL = 48;
  347.  
  348.     strcpy (pc.SP, nam);
  349.  
  350.     Regs.r_ax = 0xE300;
  351.  
  352.     Regs.r_es = FP_SEG (&pr);
  353.     Regs.r_di = FP_OFF (&pr);
  354.  
  355.     Regs.r_ds = FP_SEG (&pc);
  356.     Regs.r_si = FP_OFF (&pc);
  357.  
  358.     intr (33, &Regs);
  359.  
  360.     return (Regs.r_ax);
  361. }
  362.  
  363.  
  364. prntbyt(value)
  365. BYTE value;
  366. {
  367.     if (value == 0)
  368.         printf ("00");
  369.     else if (value < 0x10)
  370.         printf ("0%X", value);
  371.     else
  372.         printf ("%X", value);
  373. }
  374.  
  375.  
  376. void New_Netware ()
  377. {
  378.     Regs.r_ax = 0xE300;
  379.  
  380.     cc.SL.wh = 0x00;                /* request packet length    */
  381.     cc.SL.wl = 0x01;
  382.  
  383.     cr.RL.wh = 0x00;        /* reply packet length        */
  384.     cr.RL.wl = 0xff;
  385.  
  386.     cc.FNC = 0x46;
  387.  
  388.     cr.AL = 0x00;
  389.     cr.MOID.al = 0x00;
  390.     cr.MOID.ah = 0x00;
  391.     cr.MOID.bl = 0x00;
  392.     cr.MOID.bh = 0x00;
  393.  
  394.     Regs.r_es = FP_SEG (&cr);
  395.     Regs.r_di = FP_OFF (&cr);
  396.  
  397.     Regs.r_ds = FP_SEG (&cc);
  398.     Regs.r_si = FP_OFF (&cc);
  399.  
  400.     intr (33, &Regs);
  401.     
  402.     if ((cr.MOID.al == 0x00) && (cr.MOID.ah == 0x00) && (cr.MOID.bl == 0x00) && (cr.MOID.bh == 0x00))
  403.     {
  404.         printf ("This utility requires Advanced Netware to run.\n");
  405.         exit();
  406.     }
  407.     if (cr.AL != 0x33)
  408.     {
  409.         printf ("You must have supervisor rights to use this program.\n");
  410.         exit();
  411.     }
  412. }
  413.  
  414. void Logged_In ()
  415. {
  416.     Regs.r_ax = 0xE300;
  417.  
  418.     nr.RL.wh = 0x00;        /* set reply buffer to 256 */
  419.     nr.RL.wl = 0xFF;
  420.  
  421.     nc.SL.wh = 0x00;            /* packet request length = 5 */
  422.     nc.SL.wl = 0x05;                /* char = 1  -  longs = 4    */
  423.  
  424.     Regs.r_es = FP_SEG (&nr);
  425.     Regs.r_di = FP_OFF (&nr);
  426.  
  427.     Regs.r_ds = FP_SEG (&nc);
  428.     Regs.r_si = FP_OFF (&nc);
  429.  
  430.     nc.FNC = 0x36;
  431.  
  432.     nc.UOID.ah = cr.MOID.ah;            /* use user id obtained earlier */
  433.     nc.UOID.al = cr.MOID.al;
  434.     nc.UOID.bh = cr.MOID.bh;
  435.     nc.UOID.bl = cr.MOID.bl;
  436.  
  437.     intr (33, &Regs);
  438.  
  439.     if ((Regs.r_ax & 0x00ff) != 0)
  440.     {
  441.         printf ("You must be logged into the network to run this program.\n");
  442.         exit();
  443.     }
  444. }
  445.  
  446.  
  447. main (argc, argv)
  448. int argc;
  449. char *argv[];
  450. {
  451.     New_Netware ();
  452.  
  453.     Logged_In ();
  454.  
  455.     Users (strupr(argv[1]));
  456. }
  457.